package javase0823.miao;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public abstract class Animal {

    public Animal() {
        //System.out.println("init");
    }
    static int n = 0;

    static int file = 0;

    static {
        File f = new File("0823");
        if (f.exists()) {
            file = 1;
           // System.out.println(1);
        } else {
            try {
                f.createNewFile();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            file = 0;
           // System.out.println(2);
        }
    }


    public static Animal getInstance(){
        //System.out.println("file:" + file);
        if (file == 0) {
            return  new Kitty();
        }

        if (n == 0) {
            n++;
            return  new Kitty();
        }

        String s = UUID.randomUUID().toString();
        boolean flag = true;

        /*s = s.substring(0, 1);//16  8 0-7
        if ("01234567".contains(s)) {
            flag = false;
        }*/

        char c = s.charAt(0);
        if (c >= '0' && c <= '7') {
            flag = false;
        }

        if (flag) {
            return new Kitty();
        } else {
            return new Puppy();
        }

    }
    public abstract void foo();
}
